import 'package:get/get.dart';

import '../../../blt/BltManager.dart';
import '../../../event/DataCallBack.dart';
import '../../../routes/app_pages.dart';
import '../../../utils/NetWorkUtil.dart';
import '../../../utils/PermissionUtil.dart';
import '../../../widget/tips.dart';

class PowerOningController extends GetxController {

  var checkbox_checked = false.obs;

  @override
  void onInit() {
    super.onInit();
    //PermissionUtil.requestPermission();
  }

  @override
  void onReady() {
    super.onReady();
  }

  @override
  void onClose() {
    super.onClose();
  }


  void connectRobot() async {

    // 绑定前检查,网络, 蓝牙和位置信息.
    bool isNetWork = await NetWorkUtil.checkNetWorkIsAvailable();
    if (!isNetWork) {
      Tips.showToast('网络不可用.');
      return;
    }

    bool bltAndLocation = await checkBlueteethAndLocationDisable();

    if (bltAndLocation) {
      Get.toNamed(Routes.PERMISSION_SETTING);

      return;
    }


    bool permissionAllGranted = await PermissionUtil.checkPermission();
    if (!permissionAllGranted) {
      Get.toNamed(Routes.PERMISSION_SETTING);
      return;
    }


    //如果有正在连接得机器,给断开.
    BltManager.instance.disConnectDevice();

    Get.toNamed(Routes.DEVICE_CONNECTION);

   /* BltManager.instance.scanDevices(scanDeviceCallBack: DataCallBack(
        deviceCallBack: (param) {
          //设备连接成功.
          Get.toNamed(Routes.CONNECT_SUCESS);
        }
    ));*/
  }



  Future<bool> checkBlueteethAndLocationDisable () async {
    if (await PermissionUtil.locationDisabled()) {
      return true;
    }
    if (await PermissionUtil.bluetoothDisabled()) {
      return true;
    }
    return false;
  }




}
